﻿using System;
using System.IO;

namespace Engine.FileFormats3D.WR2TerrainLoader.Misc
{
    public class TexturePropertie
    {
        #region Private Fields

        private const byte VERSION = 0x01;
        private bool enlite;
        private string groundName;
        private bool hasGras;
        private string textureName;

        #endregion Private Fields

        #region Public Constructors

        public TexturePropertie(string textureName, string groundName, bool hasGras, bool enlite)
        {
            this.textureName = textureName;
            this.groundName = groundName;
            this.hasGras = hasGras;
            this.enlite = enlite;
        }

        #endregion Public Constructors

        #region Public Properties

        public bool Enlite
        {
            get { return enlite; }
            set { enlite = value; }
        }

        public string GroundName
        {
            get { return groundName; }
            set { groundName = value; }
        }

        public bool HasGras
        {
            get { return hasGras; }
            set { hasGras = value; }
        }

        public string TextureName
        {
            get { return textureName; }
            set { textureName = value; }
        }

        #endregion Public Properties

        #region Public Methods

        public static TexturePropertie FromStream(BinaryReader br)
        {
            switch (br.ReadByte())
            {
                case 0x01:
                    return LoadV1(br);

                default:
                    throw new Exception("Unsupport File Format!!");
            }
        }

        public void ToStream(BinaryWriter bw)
        {
            bw.Write(VERSION);
            bw.Write(this.textureName);
            bw.Write(this.groundName);
            bw.Write(this.hasGras);
            bw.Write(this.enlite);
        }

        public override string ToString()
        {
            return this.textureName;
        }

        #endregion Public Methods

        #region Private Methods

        private static TexturePropertie LoadV1(BinaryReader br)
        {
            return new TexturePropertie(br.ReadString(), br.ReadString(), br.ReadBoolean(), br.ReadBoolean());
        }

        #endregion Private Methods
    }
}